﻿using Prism.Commands;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Input;

namespace EntityClassMaker.Mods
{
    public class LoginMod: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }


        private bool lockhostcheckbox = false;

        public bool LockHostCheckBox
        {
            get
            {
                return lockhostcheckbox;
            }
            set
            {
                lockhostcheckbox = value;
                NotifyPropertyChanged("LockHostCheckBox");
            }
        }

        /// <summary>
        /// 验证输入是否正确
        /// </summary>
        public bool LoginTextCorrect = false;

        private string dbserverip = string.Empty;
        /// <summary>
        /// 数据库IP
        /// </summary>
        public string DBServerIP
        {
            get
            {
                return dbserverip;
            }
            set
            {
                if (ISCorrectIPSite(ref value))
                {
                    ConnectionVisb = Visibility.Visible;
                    dbserverip = value;
                    LoginTextCorrect = true;
                    ImagePath = "/Image/yes.net.png";
                }
                else
                {
                    LoginTextCorrect = false;
                    dbserverip = "你就不能吧IP输对?";
                    ConnectionVisb = Visibility.Visible;
                    ImagePath = "/Image/error.net.png";
                }
               
                NotifyPropertyChanged("DBServerIP");
            }
        }

        /// <summary>
        /// 判断输入值是否为IP值
        /// </summary>
        /// <param name="IPSite"></param>
        /// <returns></returns>
        private bool ISCorrectIPSite(ref string IPSite)
        {
            try
            {
                IPAddress ipTry = IPAddress.Parse(IPSite);
                IPSite = ipTry.ToString();
                return true;
            }
            catch
            {
                return false;
            }
        }

       

        private string dbname = string.Empty;
        /// <summary>
        /// 数据库登录名
        /// </summary>
        public string DBName
        {
            get
            {
                return dbname;
            }
            set
            {
                dbname = value;
                NotifyPropertyChanged("DBName");
            }
        }

        private string dbpassword = string.Empty;
        /// <summary>
        /// 数据库连接密码
        /// </summary>
        public string DBPassword
        {
            get
            {
                return dbpassword;
            }
            set
            {
                dbpassword = value;
                NotifyPropertyChanged("DBPassword");
            }
        }

        private string imagepath = "/Image/yes.net.png";
        /// <summary>
        /// 图片展示路径
        /// </summary>
        public string ImagePath
        {
            get
            {
                return imagepath;
            }
            set
            {
                imagepath = value;
                NotifyPropertyChanged("ImagePath");
            }
        }


        private Visibility connectionvisb = Visibility.Collapsed;
        /// <summary>
        /// 提示图标
        /// </summary>
        public Visibility ConnectionVisb
        {
            get
            {
                return connectionvisb;
            }
            set
            {
                connectionvisb = value;
                NotifyPropertyChanged("ConnectionVisb");
            }
        }
    }
}
